package exercise;

import java.util.ArrayList;

public class FizzBuzz {
    private int n;
    private int value =1;
//    ArrayList<String> list = new ArrayList<>();
    public FizzBuzz(int n) {
        this.n = n;

    }

    public void fizz() throws InterruptedException {
        synchronized (this) {
			while(value<=n){
				if(value%3==0&&value%5!=0){
					Test.list1.add("fizz");
					System.out.print("fizz,");
					value++;
					this.notifyAll();
				}else{
					this.wait();
				}
			}
		}
    }

    public void buzz() throws InterruptedException {
        synchronized (this) {
			while(value<=n){
				if(value%5==0&&value%3!=0){
					Test.list1.add("buzz");
					System.out.print("buzz,");
					value++;
					this.notifyAll();
				}else{
					this.wait();
				}
			}
		}
    }

    public void fizzbuzz() throws InterruptedException {
        synchronized (this) {
			while(value<=n){
				if(value%3==0&&value%5==0){
					Test.list1.add("fizzbuzz");
					System.out.print("fizzbuzz,");
					value++;
					this.notifyAll();
				}else{
					this.wait();
				}
			}
		}
    }

    public void number() throws InterruptedException {
    	synchronized (this) {
			while(value<=n){
				if(value%3!=0&&value%5!=0){
					Test.list1.add(""+value);
					System.out.print(value+",");
					value++;
					this.notifyAll();
				}else{
					this.wait();
				}
			}
		}
    }
}
